package com.own.component.token.config;

import com.own.component.autoconfig.property.token.TokenProperty;
import com.own.component.client.base.RequestClientManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * TokenInstance
 *
 * @author chenxueli
 * @date 2023-11-07 19:48:39
 */
@Component
@DependsOn(value = {
        "store",
        "tokenStoreConfig",
        "userIdStoreConfig"
})
public class TokenInstance {

    public static TokenInstance INSTANCE;

    @Resource
    public TokenProperty tokenProperty;

    @Resource
    private RequestClientManager requestClientManager;

    @Resource
    private HttpServletRequest request;

    @PostConstruct
    private void init() {
        INSTANCE = this;
    }

    /**
     * 客户端信息
     *
     * @return 客户端信息
     */
    public String client() {
        var client = requestClientManager.client(request);
        return StringUtils.isBlank(client) ? tokenProperty.getDefaultClient() : client;
    }

}
